/**
\file IO.h
*/
#pragma once
#include <lostlbase.h>
#include <System.h>
#include "LoSetupapi.h"

namespace lo {

	class Printer
	{
	public:
		Printer(HANDLE _handle, const char *deviceName, const char *friendlyName);
		~Printer();
		void		Close();
		void		Delete();
		/** Returns true if the port exists optionally matching the monitor name. */
		static bool	DoesPortExist(const char *portName, const char *monitorName = nullptr);
		void		EndDoc();
		void		EndPage();
		static auto_ptr<unsigned char> GetPrinterInfo(const char *printer, int level);
		string		GetPrinterName();
		static Printer	Open(const char *printer,ACCESS_MASK mask = PRINTER_ACCESS_ADMINISTER);
		void		SendRawData( vector<unsigned char>& data );
		static void	ShowPrinterFolder();
		DWORD		StartDoc( const char *documentName, const char *outputFile, const char *dataType = "RAW" );
		void		StartPage();
		void		Write( vector<unsigned char>& data );
	private:
		Printer(HANDLE printer) : m_printer(printer) {}
		HANDLE	m_printer;
	};

	class PrinterDC
	{
	public:
		PrinterDC(const char *printerName);
		~PrinterDC();
		HBITMAP	CreateDIBitmap( _In_ const BITMAPINFOHEADER *lpbmih, _In_ DWORD fdwInit, _In_ const VOID *lpbInit, _In_ const BITMAPINFO *lpbmi, _In_ UINT fuUsage );
		HBITMAP	CreateDIBSection( _In_ const BITMAPINFO *pbmi, _In_ UINT iUsage, _Out_ VOID **ppvBits, _In_ HANDLE hSection, _In_ DWORD dwOffset );
		void	EndDoc();
		void	EndPage();
		/** Prints a bitmap to the full page size by stretching it to fit to the physical. The Bitmap will be cropped by the physical margins. */
		void	PrintFullPageBitmap( HBITMAP bitmap);
		void	StartDoc( const char *documentName, const char *outputFile, const char *dataType );
		void	StartPage();
	private:
		HDC			m_hdc;
	};

}